<?php
/**
 * Created by PhpStorm.
 * User: tonyliangli
 * Date: 16/3/28
 * Time: 13:36
 */

namespace Api\Controller;

class RedisController extends CommonController
{

    //session写入Redis
    public function testSession() {

        session('test','test123');

        $test = $_SESSION['test'];

        print_r($test);

    }

    public function session() {

        $test1 = $_SESSION['test'];

        print_r($test1);

        session('test',null);

        $test2 = session('test');

        var_dump($test2);

    }

    //缓存写入Redis
    public function testCache() {

        S('key', '123');

        $key = S('key');

        print_r($key);

    }

    //继承ThinkPHP连贯操作
    public function testRedisDB() {

        //实例化Redis时自动切换数据库为RedisDB
        $Redis = D('Redis');

        //key-value类型,支持批量操作
        $Redis->type("string")->add(array('123'=>'456'));

        print_r($Redis->type("string")->field(array('123'))->find());

        $data=array(
            "str1"=>"123", //一个key，对应一个值
            "str2"=>"456",
            "str3"=>"789",
        );

        $Redis->type("string")->add($data);

        print_r($Redis->type("string")->field(array('str1','str2','str3'))->select());

    }

}